package trlygjj.tanruiliyigenjinjin.web.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.DataDictionaryItem;
import trlygjj.tanruiliyigenjinjin.service.IDataDictionaryItemService;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;
import trlygjj.tanruiliyigenjinjin.util.PermissionName;

import java.util.List;

/**
 * Created by user on 2018/7/11.
 */
@Controller
@RequestMapping("dataDictionaryItem")
public class DataDictionaryItemController {

    @Autowired
    private IDataDictionaryItemService dataDictionaryItemServiceService;

    /**
     * 删除
     * @param dataDictionaryItemId 要删除的员工对象id
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequiresPermissions("dataDictionaryItem:delete")
    @PermissionName("数据字典明细删除")
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long dataDictionaryItemId){
        JsonResult result = new JsonResult();
        try{
            dataDictionaryItemServiceService.deleteByPrimaryKey(dataDictionaryItemId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     *更新
     * @param dataDictionaryItem 要更新的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequiresPermissions("dataDictionaryItem:update")
    @PermissionName("数据字典明细更新")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(DataDictionaryItem dataDictionaryItem){
        JsonResult result = new JsonResult();
        try{
            dataDictionaryItemServiceService.updateByPrimaryKey(dataDictionaryItem);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     * 保存
     * @param dataDictionaryItem 要保存的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequiresPermissions("dataDictionaryItem:save")
    @PermissionName("数据字典明细保存")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(DataDictionaryItem dataDictionaryItem){
        JsonResult result = new JsonResult();
        try{
            dataDictionaryItemServiceService.insert(dataDictionaryItem);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    @RequiresPermissions("dataDictionaryItem:selectByParentId")
    @PermissionName("查询数据字典明细")
    @RequestMapping("selectByParentId")
    @ResponseBody
    public List<DataDictionaryItem> selectByParentId(Long id){
        List<DataDictionaryItem> dataDictionaryItems = dataDictionaryItemServiceService.selectByParentId(id);
        return dataDictionaryItems;
    }



}
